{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn import datasets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(100, 2)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X, y = datasets.make_moons(noise=0.15, random_state=666)\n",
    "X.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYYAAAD8CAYAAABzTgP2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAIABJREFUeJzt3X2sHfV95/H3F7CN7iY0fkp4vNeQEjaJlPJwhUhSdZMmJMh/YKqSLdRNjRZkQZbtrqJd1QgpWpG1NvSPzaq7RVuXpHFqi4fSpnGzUMrjRrsNhEtkMA9rbBwMXnvDBRMKYgvBfPePmVPPOZ5zzpwzT7+Z+byk0TlnZs45vzv3zHzn92zujoiISM9xdSdARETCosAgIiJ9FBhERKSPAoOIiPRRYBARkT4KDCIi0keBQURE+igwiIhIHwUGERHpc0LdCZjGqlWrfM2aNXUnQ0SkUR5//PFX3H31uP0aGRjWrFnDwsJC3ckQEWkUM9ufZT8VJYmISB8FBhER6aPAICIifRQYRESkTyGBwcy+bWYvm9lTQ7avN7Mn4+XvzOxXEtteMLNdZrbTzFSjLCJSs6JyDN8BLhmx/afAP3P3TwBfB7YMbP+su5/r7vMFpUdERKZUSHNVd/+hma0Zsf3vEi8fAU4v4ntFRKR4ddQxXA3ck3jtwN+a2eNmtrGG9EhRtm+HNWvguOOix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X3g2Z2FvCgme1y9+eLSeFYWY5Xpcd0jCxp+WvgNnd/28yuJcrthDq3eUjHNoufEA3p8KaZrQX+Cji75jRhZu8D/gL4N+7+94ObU94S8jEGFBj6uPvnc37EASB5h3g6cDDnZw41Kr1m9jMzO8XdD8VZ15eHfMbB+HGfmT1MdNdTVWDIcrx6+xwwsxOAX6K+4oax6XX3VxMv/wS4uYJ0TavS32teyYuuu99tZreY2Sp3r21MIjNbQhQUtrv7X6bs0qhj3KOipGI9BpxtZmea2VKiytLKW/rEdgAb4ucbgGNyPGa23MyWxc9XAZ8GnqkshdmOV/LvuBx40ONavRqMTe9A+fGlROXOodoB/G7ccuYi4PVe8WOIzOzkXv2SmV1IdP16dfS7Sk2PAd8CnnX3/zRkt0Yd439Ud+13UxbgN4ii/9vAz4B74/WnAncn9ltL1DrheaIiqLrSuxJ4ANgTP66I188Dt8bPPwXsImpdswu4uoZ0HnO8gJuAS+PnJwJ/DuwFfgycVfPvYFx6/yPwdHxMHwL+aY1pvQ04BPwi/u1eDVwLXBtvN+CP4r9lF0Na2wWU3usTx/YR4FM1p/dXiYqFngR2xsvakI9x1kU9n0VEpI+KkkREpI8Cg4iI9FFgEBGRPgoMIiLSR4FBRET6KDCIiEi0SwkWAAAAEklEQVQfBQYREemjwCAiIn3+P0/C9ES6wQLfAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x2a512265978>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(X[y==0,0], X[y==0,1], color='red')\n",
    "plt.scatter(X[y==1,0], X[y==1,1], color='blue')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 使用多项式特征的SVM"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.preprocessing import PolynomialFeatures, StandardScaler\n",
    "from sklearn.svm import LinearSVC\n",
    "from sklearn.pipeline import Pipeline\n",
    "\n",
    "def PolynomialSVC(degree, C=1.0):\n",
    "    return Pipeline([\n",
    "        ('poly', PolynomialFeatures(degree=degree)),\n",
    "        ('std_scaler', StandardScaler()),\n",
    "        ('linearSVC', LinearSVC(C=C))\n",
    "    ])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Pipeline(memory=None,\n",
       "     steps=[('poly', PolynomialFeatures(degree=3, include_bias=True, interaction_only=False)), ('std_scaler', StandardScaler(copy=True, with_mean=True, with_std=True)), ('linearSVC', LinearSVC(C=1, class_weight=None, dual=True, fit_intercept=True,\n",
       "     intercept_scaling=1, loss='squared_hinge', max_iter=1000,\n",
       "     multi_class='ovr', penalty='l2', random_state=None, tol=0.0001,\n",
       "     verbose=0))])"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "poly_svc = PolynomialSVC(degree=3, C=1)\n",
    "poly_svc.fit(X, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "def plot_decision_boundary(model, axis):\n",
    "    x0, x1 = np.meshgrid(\n",
    "        np.linspace(axis[0], axis[1], int((axis[1]-axis[0])*100)),\n",
    "        np.linspace(axis[2], axis[3], int((axis[3]-axis[2])*100))\n",
    "    )\n",
    "    x_new = np.c_[x0.ravel(), x1.ravel()]\n",
    "    \n",
    "    y_predict = model.predict(x_new)\n",
    "    zz = y_predict.reshape(x0.shape)\n",
    "    from matplotlib.colors import ListedColormap\n",
    "    custom_cmap = ListedColormap(['#EF9A9A', '#FFF59D', '#90CAF9'])\n",
    "    plt.contourf(x0, x1, zz, linewidth=5, cmap=custom_cmap)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\fangyang\\Anaconda3\\lib\\site-packages\\matplotlib\\contour.py:967: UserWarning: The following kwargs were not used by contour: 'linewidth'\n",
      "  s)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAD8CAYAAAB3u9PLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAIABJREFUeJzt3X+QHOV95/H3V8MKGSwjCc6IAI6Mg+8ClSvhyKwdzndU4kvJcCWsxBRgyZGv7GxxOl9EXV3VbaBKBFLHyXeuq8gFOp/iHxE/ArIdK1EOIs4/yykSNiguMCwkNlA+swbBgWQsJGQtu8/9MT1idtQz0zPzdD9Pd39eVVuanendftQ709/nx/d5HnPOISIisih0AUREJA4KCCIiAiggiIhIQgFBREQABQQREUkoIIiICOApIJjZF83sJTN7osvrl5vZq2b2aPK11cd5RUTEn1M8/Z4/AW4H7uxxzF875/6Np/OJiIhnXloIzrnvAgd9/C4REQnDVwshi/eb2WPA88B/cs5Ndx5gZhPABMDpp576qxeuXFlg8USkaK+85czQRaic5/7hey875/7JMD9bVED4HvCLzrnXzOwK4M+BCzsPcs7tBHYCXLJqlfv2TTcVVDwRKdqyDQ22T28MXYzKueHSU//vsD9bSJaRc+5nzrnXkscPAGNmdlYR5xYRkWwKCQhmttLMLHl8aXLeV4o4t4iIZOOly8jM7gUuB84ysxngZmAMwDn3OeAjwL8zszeA14FrnZZZFRGJipeA4Jy7rs/rt9NMSxURAdD4QYQ0U1lERAAFBBERSSggiIgIoIAgIiIJBQQREQEUEEQkgGUbGqGLICkUEESkcEo5jZMCgoiIAAoIIiKSUEAQERFAAUFERBIKCCIiAiggiIhIQgFBRESAYvdUlgobm5piyZ49LDp4kPkVKzi2fj2z4+OhiyUiA1BAkJGNTU1x2l13YcePA9A4eJDT7rqLo6CgIFIi6jKSkS3Zs+dEMG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d/DHy6gHINqhTLx7Tf0JxzD5jZDjM7yzlX6IJyZjZG8yZ7j3PuaymHRHE9+5VzmOtZqi4jMzvdzJa2HgO/SXNPhtjEsFzHXmBT8ngTcFLLxsyWm9mpyeOzgMsoZlnyLNenvfwfAb7lkpGyAvUtZ0ff8Tqafbmx2Qv8TpId8z7g1VZ3YkzMbGVrnMjMLqV5f3ql9095L4MBXwCecs79jy6HBb+eWco51PUsenS8x6j5epqR9+fAi8CDyfO/ADyQPL6AZqbHY8A0zS6c6Mrp3sxE+AHN2naIcp4JfBP4YfLviuT5NcDnk8doooiYAAAAnUlEQVS/BjyeXM/HgU8UWL6Trg9wK7AuebwE+ArwNPB3wAWB3pf9yvlfk/fiY8C3gX8WoIz3Ai8As8l78xPA9cD1yetGc5OqZ5K/c9csvsDl/FTbtXwY+LUAZfwXNLt/vg88mnxdEdv1zFjOga+nlq4QERGgZF1GIiKSHwUEEREBFBBERCShgCAiIoACgoiIJBQQREQEUEAQEZHE/weNE6YhcUrTcAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x2a5127711d0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_decision_boundary(poly_svc, axis=[-1.5,2.5,-1,1.5])\n",
    "plt.scatter(X[y==0,0], X[y==0,1], color='red')\n",
    "plt.scatter(X[y==1,0], X[y==1,1], color='blue')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 使用多项式和函数的SVM"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.svm import SVC\n",
    "\n",
    "def PolynomialKernelSVC(degree, C=1.0):\n",
    "    return Pipeline([\n",
    "        ('std_scaler', StandardScaler()),\n",
    "        ('kernelSVC', SVC(kernel='poly', degree=degree, C=C))  \n",
    "        # 指定kernel为poly也能实现非线性拟合, 但是结果和上面的不一样\n",
    "    ])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Pipeline(memory=None,\n",
       "     steps=[('std_scaler', StandardScaler(copy=True, with_mean=True, with_std=True)), ('kernelSVC', SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,\n",
       "  decision_function_shape='ovr', degree=3, gamma='auto', kernel='poly',\n",
       "  max_iter=-1, probability=False, random_state=None, shrinking=True,\n",
       "  tol=0.001, verbose=False))])"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "poly_kernel_svc = PolynomialKernelSVC(degree=3)\n",
    "poly_kernel_svc.fit(X, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\fangyang\\Anaconda3\\lib\\site-packages\\matplotlib\\contour.py:967: UserWarning: The following kwargs were not used by contour: 'linewidth'\n",
      "  s)\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAD8CAYAAAB3u9PLAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAH+1JREFUeJzt3X+QXeV93/H3d9crrcEL0lo1IvywjCtS00kHHJm1Q5LSmnZk6IhsYgZkWZEZ042rMJhMM9MdmBGNOqV2p83EHltxlNhYpq4s24kSpRBR8I+SoWWD4gGDoAbBxHgtBIGl/BKyltXTP+650t275957zr3POec553xeMxpd3Xt2z6O7d8/3eZ7v93mOOecQEREZKroBIiISBgUEEREBFBBERCSigCAiIoACgoiIRBQQREQE8BQQzOwrZvaCmT3W4fXLzewVM3s4+rPNx3lFRMSft3n6Pl8FvgB8rcsxf+2c+1eeziciIp55GSE45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1PPwJs/tOgbRrZ0pvs350ft5AfBdM3vUOfe0nxZ2lOT9yeU97CFJG/4S2O2c+5mZfYrGqOafZ96ydEJ4L5P4AfBu59zrZnYl8OfA2iIaYmbvAP4UuNk592r7yzFfUsj72aOdqd/PXAOCG3wbDJxzh6O/XzCzvTSG9V4Dgod25rJdR7d2mtnzZna2c+65aDj7Qofv0Xw/nzGz79PoaWQdEJK8P81jZs3sbcCZ5D/d0LOdzrmXWv75x8Bnc2hXWqXYPqb1guacu9vMdpjZKudcrhvKmdkIjYvs151zfxZzSBDvZ6929vN+lmrKyMxON7Ox5mPgX9K4J0NoQtiuYx+wJXq8BVgysjGzlWa2PHq8CriMfLYlT/L+tLb/o8B3XZQpy1HPdrbNHW+gMZcbmn3Ab0bVMR8EXmlOJ4bEzFY380RmdimN69NL3b/KexsM+DLwhHPu9zscVvj7maSdfb2feWfHu2TNJ2lE3p8BzwP3RM//HHB39PgCGpUejwAHaUzhBNdOd6oS4Ukave0i2vlO4DvAU9Hf49Hz64A/iR7/EvBo9H4+Cnwyx/YteX+A7cCG6PEo8C3gEPA3wAUFfS57tfM/RZ/FR4DvAf+ogDbuBp4D5qPP5ieBTwGfil43Gjepejr6OXes4iu4nTe2vJcPAr9UQBt/mcb0zw+Bh6M/V4b2fiZsZ+r3U1tXiIgIULIpIxERyY4CgoiIAAoIIiISUUAQERFAAUFERCIKCCIiAiggiIhI5P8DTdRMF8OZrAYAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x2a514685860>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_decision_boundary(poly_kernel_svc, axis=[-1.5,2.5,-1,1.5])\n",
    "plt.scatter(X[y==0,0], X[y==0,1], color='red')\n",
    "plt.scatter(X[y==1,0], X[y==1,1], color='blue')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 核函数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### $min\\frac{1}{2}\\|w\\|^2 + C \\sum_{i=1}^m\\zeta_i$  , 核函数推导这里用不上正则化项,所以L1/L2无所谓\n",
    "### $s.t.\\ \\ \\ y^{(i)}(w^Tx^{(i)}+b) \\geq 1-\\zeta_i$\n",
    "#### $\\zeta_i \\geq 0$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 上面三式变成如下形式: \n",
    "### $max\\sum_{i=1}^{m}\\alpha_i - \\frac{1}{2}\\sum_{i=1}^{m}\\sum_{j=1}^{m}\\alpha_i\\alpha_j y_i y_j x_i x_j$ , i代表行, j代表列\n",
    "### $s.t.\\ \\ \\ 0 \\leq \\alpha_i\\leq C$\n",
    "### $\\sum_{i=1}^{m}\\alpha_i y_i = 0$\n",
    "\n",
    "### ===> $max\\sum_{i=1}^{m}\\alpha_i - \\frac{1}{2}\\sum_{i=1}^{m}\\sum_{j=1}^{m}\\alpha_i\\alpha_j y_i y_j K(x_i,x_j)$ "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "------\n",
    "### $K(x,y) = (x \\cdot y +1)^2 = (\\sum_{i=1}^{n}x_i y_i + 1)^2$\n",
    "#### $=\\sum_{i=1}^{n}(x_i^2)(y_i^2)+\\sum_{i=2}^{n}\\sum_{j=1}^{i-1}(\\sqrt2 x_i y_j)(\\sqrt2 x_i y_j)\n",
    "+\\sum_{i=1}^{n}(\\sqrt2 x_i)(\\sqrt2 y_j) + 1$\n",
    "### $=x' \\cdot y'$\n",
    "### $x' = (x_n^2, \\ldots, x_1^2, \\sqrt2 x_n x_{n-1}, \\ldots, \\sqrt2 x_n, \\ldots, \\sqrt2 x_1, 1)$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "----\n",
    "### $K(x,y) = (x \\cdot y + c)^d = (\\sum_{i=1}^{n}x_i y_i + c)^d$ , d 和 c为超参数\n",
    "#### sklearn.svm.SVC的参数里面, 如果kernel='poly'为多项式核函数, \n",
    "#### 在其基础上, 可以指定degree为上面的d, coef0为上面的c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
